package com.dj.servlet;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.server.RestfulServer;
import com.dj.controller.EncounterController;
import com.dj.controller.JcbgController;
import com.dj.controller.PatientController;
import com.dj.controller.ProcedureRequestController;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import java.util.List;

@Component
public class MyServlet extends RestfulServer {

	private static final long serialVersionUID = 1647713369719287699L;

//	@Override
//	protected void initialize() throws ServletException {
//		// ...Configure resource providers, etc...
//
//		// Create a context, set the error handler and instruct
//		// the server to use it
//		FhirContext ctx = FhirContext.forDstu3();
//		ctx.setParserErrorHandler(new StrictErrorHandler());
//		setFhirContext(ctx);
//	}

	@Autowired
	private PatientController patientController;

	@Autowired
	private EncounterController encounterController;

	@Autowired
	private ProcedureRequestController procedureRequestController;

	@Autowired
	private JcbgController jcbgController;

	@PostConstruct
	public void initProvider() {
		List<Object> plainControllers = Lists.newArrayList();

		//添加对应的服务提供者
		plainControllers.add(patientController);
		plainControllers.add(encounterController);
		plainControllers.add(procedureRequestController);
		plainControllers.add(jcbgController);

		setPlainProviders(plainControllers);
	}

}
